package com.grts.mall.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.grts.mall.mapper.CategoryMapper;
import com.grts.mall.pojo.Category;
import com.grts.mall.pojo.CategoryExample;

@Service
public class CategoryServiceImpl implements CategoryService {

	@Autowired
	private CategoryMapper categoryMapper;
	
	@Override
	public long count() {
		return categoryMapper.countByExample(new CategoryExample());
	}

	@Override
	public List<Category> findPageList(int page, int limit) {
		int skip = (page - 1) * limit;
		int take = limit;
		return this.categoryMapper.selectPageList(skip, take);
	}

	@Override
	public void save(Category category) {
		this.categoryMapper.insert(category);
	}

	@Override
	public void del(Long cid) {
		CategoryExample example = new CategoryExample();
		example.createCriteria().andCidEqualTo(cid);
		this.categoryMapper.deleteByExample(example);
	}

	@Override
	public Category findById(Long cid) {
		
		return this.categoryMapper.selectByPrimaryKey(cid);
	}

	@Override
	public void update(Category category) {
		this.categoryMapper.updateByPrimaryKeySelective(category);
	}

	@Override
	public void groupDel(List<Long> cid) {
		CategoryExample example = new CategoryExample();
		example.createCriteria().andCidIn(cid);
		this.categoryMapper.deleteByExample(example);
	}

	@Override
	public List<Category> findall() {
		CategoryExample example = new CategoryExample();
		return this.categoryMapper.selectByExample(example);
	}

}
